Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

3.6K
Vistas
Error launching Flask app with error "Failed to find Flask application"

I'm new to Flask. To launch the flask app, I did python -m flask run but I repeatedly get the error:

Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one.

I am using a virtualenv on a Windows 10 machine

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "Hello, World!"

if __name__ == '__main__':
    app.run(debug=True)

I expected a web server to start and to be able to navigate to localhost http://127.0.0.1:5000/ where I could view Hello, World! on my browser, but that never happened.

over 4 years ago · Santiago Trujillo
10 Respuestas
Responde la pregunta

0

Instead of just "flask" use FLASK_APP=theflaskapp.py, like what Marco suggested:

 env FLASK_APP=theflaskapp.py python -m flask run

This should fix it, if not, make sure you are executing the command to run the script in the same directory as it. You should also check if the problem is in flask or not by running "python theflaskapp.py" (In the same directory as the flask app still) and see if it works at all.

over 4 years ago · Santiago Trujillo Denunciar

0

Try removing the spaces from this line of code, this is what fixed it for me when I had this error:

app=Flask(__name__)
over 4 years ago · Santiago Trujillo Denunciar

0

Another working option is executing this command instead of flask run :

flask run --host=0.0.0.0

I had the same issue and I tried all the mentioned answers here but couldn't work finally this did the trick.

over 4 years ago · Santiago Trujillo Denunciar

0

In my case was a very simple issue, the activate.bat file was setup as Macintosh (CR) I changed to Windows (CR LF) and that worked for me.

Explanation: In windows OS, for the instruction to take effect, for example [set FLASK_ENV = development] a strong carriage return is needed, such as the (CR LF), that is what I could verify in my case. You can try to run the SET instruction in the console, cmd, and check if the FLASK settings are reflected. I understand that it is more a problem of the configuration of the environment and not of the application itself.

over 4 years ago · Santiago Trujillo Denunciar

0

You need to specify what file you want to work with. Try this.

For Windows:

set FLASK_APP=app.py
python -m flask run

For Mac OS and Linux:

export FLASK_APP=app.py
python -m flask run
over 4 years ago · Santiago Trujillo Denunciar

0

I'm getting the same error. The problem is you have to set the environment variable FLASK_APP in current project.

However, I have easiest way to solve this problem. Instead of using flask run command you can use python app.py.

"app.py" is your application entry point.

over 4 years ago · Santiago Trujillo Denunciar

0

I had a similar problem. It seems to work fine from the command prompt with python app.py. However, it would fail to launch with VS Code Debug.

The trick was to add:

server = app.server

before calling the app.run_server() portion

over 4 years ago · Santiago Trujillo Denunciar

0

Reproducing the problem, and fixing it

Hello, I have reproduced the problem This is the error code:

Error: Failed to find Flask application or factory in module "src.app". Use "FLASK_APP=src.app:name to specify one.

Steps of reproducing the error:

  1. Create a file called app.py
  2. inside app.py put this code:
from flask import Flask

def create_app():
    app = Flask("abc")

    @app.route('/')
    def hello_world():
        return 'Hello, World!'

Or let the file be empty, like this:

# This is an empty file
# There is no flask application here
  1. Inside CLI run these commands:
export FLASK_APP=app.py
flask run
  1. watch the error appear on the screen

Solution 1 :

  1. make the function return the app
  2. Clearly create a variable called app and make it equal to the return value of the function, like this:
from flask import Flask
def create_app():
    app = Flask(__name__)
    @app.route('/')
    def hello_world():
        return 'Hello, World!'
    return app
app = create_app()

Solution 2: Get the app outside of the function:

from flask import Flask

app = Flask("abc")

@app.route('/')
def hello_world():
    return 'Hello, World!'
over 4 years ago · Santiago Trujillo Denunciar

0

solution for flask Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory. on windows when you tried set FLASKAPP=appname.py if your using PowerShell and if get the above error try this 👇👇

$env:FLASK_APP = "filename"
$env:FLASK_ENV = "development"
Flask run

try it if your having trouble launching the flask app.

over 4 years ago · Santiago Trujillo Denunciar

0

The simplest way to run your app without getting any issue is to create the app then run python app.py

from flask import (
    Flask, 
    jsonify
)

# Function that create the app 
def create_app(test_config=None ):
    # create and configure the app
    app = Flask(__name__)

    # Simple route
    @app.route('/')
    def hello_world(): 
        return jsonify({
           "status": "success",
            "message": "Hello World!"
        }) 
     
    return app # do not foget to return the app

APP = create_app()

if __name__ == '__main__':
    # APP.run(host='0.0.0.0', port=5000, debug=True)
    APP.run(debug=True)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda